package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class CloneTest extends JFrame {

	private JPanel contentPane;
	private JButton btnNewButton;
	private JScrollPane scrollPane;
	private JTextArea result;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CloneTest frame = new CloneTest();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CloneTest() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 386, 305);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		contentPane.add(getBtnNewButton());
		contentPane.add(getScrollPane());
	}

	private JButton getBtnNewButton() {
		if (btnNewButton == null) {
			btnNewButton = new JButton("Copy Clone");
			btnNewButton.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					Point p = new Point();
					p.x=100;
					p.y=200;
					
					//객체 복사
					Point temp = (Point)p.clone();
					//Before Data Changed
					result.append("\n\nBefore Data Changed=====================\n");
					result.append("p.x = " + p.x);
					result.append("\np.y = " + p.y);
					result.append("\ntemp.x = " + temp.x);
					result.append("\ntemp.y = " + temp.y);
					
					//After Data Changed
					temp.x=300;
					temp.y=550;
					result.append("\n\nAfter Data Changed=======================");
					result.append("\np.x = " + p.x);
					result.append("\np.y = " + p.y);
					result.append("\ntemp.x = " + temp.x);
					result.append("\ntemp.y = " + temp.y);					
				}
			});
			btnNewButton.setBounds(12, 10, 346, 23);
		}
		return btnNewButton;
	}
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setBounds(12, 39, 346, 218);
			scrollPane.setViewportView(getResult());
		}
		return scrollPane;
	}
	private JTextArea getResult() {
		if (result == null) {
			result = new JTextArea();
		}
		return result;
	}
}
